{include title="新建角色" keywords="" description=""  file='../application/admin/view/layout/header.html' /}

<body>
<style>
    .permission-list > dd > dl > dd {
        margin-left: 0px;
    }
</style>
<article class="page-container">
    <form action="{:url('admin/admin_role/roleAdd')}" method="post" class="form form-horizontal" id="form-admin-role-add">
        {:token()}
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="请输入角色名称" id="roleName" name="name">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">备注：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="请输入备注" id="" name="remark">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">角色状态：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" name="status">
                            <option value="1">正常</option>
                            <option value="0">禁用</option>
                    </select>
		        </span>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">角色权限：</label>
            <div class="formControls col-xs-8 col-sm-9">
                {foreach $menu_tree as $k => $v}
                    {if ($v['pid']==0)}
                        <dl class="permission-list">
                            <dt>
                                <label>
                                    <input type="checkbox" value="{$v['id']}" name="ids[]" id="user-Character-0">
                                    {$v['name']}</label>
                            </dt>
                            {foreach $menu_tree as  $vv}
                                {if ($vv['pid']==$v['id'])}
                                    <dd>
                                        <dl class="cl permission-list2">
                                            <dd>
                                                <label class="permission-list3">
                                                    <input type="checkbox" value="{$vv['id']}" name="ids[]" id="user-Character-0-0">
                                                    {$vv['name']}
                                                </label>

                                                    {foreach $menu_tree as  $vvv}
                                                        {if ($vvv['level']>=2 && $vvv['top_id']==$vv['id'])}
                                                            <label class="permission-list3">
                                                                <input type="checkbox" value="{$vvv['id']}" name="ids[]" id="user-Character-0-0-0">
                                                                {$vvv['name']}
                                                            </label>
                                                        {/if}
                                                    {/foreach}
                                            </dd>
                                        </dl>

                                    </dd>
                                {/if}
                            {/foreach}
                        </dl>
                    {/if}
                {/foreach}
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
            </div>
        </div>
    </form>
</article>
<script>
    //前端验证
    var check = $(".form").Validform({
        tiptype: function (msg, o) {
            if (o.type == 3) {layer.msg(msg, {icon: 2});}
        },
        ajaxPost: true,
        callback: function (data) {
            if(data.status=='y'){
                layer.msg(data.info, {icon: 1});
                setTimeout(function(){
                    parent.location.reload();
                },1000);
            }else{
                $("[name=__token__]").val(data.token);
            }
        }
    });
    check.addRule([
        {ele: "[name='name']", datatype: '*1-10', nullmsg: '请填写角色名称', errormsg: "角色名称1至10位之间"},
        {ele: "[name='remark']", datatype: '*0-30', nullmsg: '请填写备注', errormsg: "备注在0-30位之间"}
    ]);
</script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $(function(){
        $(".permission-list dt input:checkbox").click(function(){
            $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
        });
        $(".permission-list2 dd input:checkbox").click(function(){
            var a =$(this).parent().parent().find("input:checked").length;
            var b=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
            if($(this).prop("checked")){
                $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
            } else {
                if(a==0){
                    $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
                }
                if(b==0){
                    $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
                }
            }
        });

        $(".permission-list3").find("input").on('click',function () {
            if ($(this).parent().index()==0){
                $(this).prop("checked",$(this).prop("checked"));
            }else{
                if($(this).prop("checked")){
                    $(this).parent().parent().find("input:checkbox").first().prop("checked",true);
                }
            }
        })
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>